import axios from 'axios'
export default {
  /*
   ** Nuxt 部署目标
   **  'server'：用于服务器端渲染 默认
   **  'static'：对于静态网站
   */
  target: "static",
  // Global page headers (https://go.nuxtjs.dev/config-head)
  head: {
    title: 'llllll',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: '' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },

  // Global CSS (https://go.nuxtjs.dev/config-css)
  css: [
    "~assets/css/animate.css",
    "~assets/css/normailze.css",
    // 'element-ui/lib/theme-chalk/index.css'
  ],

  // Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
  plugins: [
    '@/plugins/element-ui',
    '@/plugins/i18n',

    
    // {
    //   src:'@/plugins/axios',
    //   ssr:false  //默认  客户端和服务端都会被拦截   这是设置false 关闭服务端求情拦截
    // }
  ],

  router:{
     middleware:['auth','i18n']
  },

  // Auto import components (https://go.nuxtjs.dev/config-components)
  components: true,

  // Modules for dev and build (recommended) (https://go.nuxtjs.dev/config-modules)
  buildModules: [
  ],

  // Modules (https://go.nuxtjs.dev/config-modules)
  modules: [
    // https://go.nuxtjs.dev/axios
    '@nuxtjs/axios',
    '@nuxtjs/proxy',//开启代理
  ],
  // axios:{
  //   proxy:true,
  //   retry:{retries:30},
  //   debug:process.env._ENV=='production'?false:true,
  //   headers:{'Content-Type':'appliaction/json','crossDemain':true},
  //   timeout:5000,
  //   prefix:'/api'
  // },
  // proxy:{
  //   '/api':{
  //     target:'http://localhost:4000',
  //     changeOrigin:true,
  //     pathRewrite:{
  //       '/api':'/'
  //     }
  //   }
  // },
  // Axios module configuration (https://go.nuxtjs.dev/config-axios)
  

  // Build Configuration (https://go.nuxtjs.dev/config-build)
  build: {
    vendor:['axios'],//防止被多次打包
    babel: {        //按需导入
             "plugins": [
              [
                "component",
                {
                  "libraryName": "element-ui",
                  "styleLibraryName": "theme-chalk"
                }
              ]
            ]
          },
    transpile: [/^element-ui/],
    extend (config, { isDev, isClient }) {
      // 音频文件 file-loader 处理，使用 <audio :src="require('@/assets/water.mp3')" controls></audio> 快速调用
      config.module.rules.push({
        test: /\.(ogg|mp3|wav|mpe?g)$/i,
        loader: 'file-loader',
        options: {
          name: '[path][name].[ext]'
        }
      })
      // 配置 eslint 检查
      // if (isDev && isClient) {
      //   config.module.rules.push({
      //     enforce: 'pre',
      //     test: /\.(js|vue)$/,
      //     loader: 'eslint-loader',
      //     exclude: /(node_modules)/
      //   })
      // }
    }
  },
   generate: {
      		// nuxt generate 生成的目录名称 
         dir: 'distapp',
        // Nuxt.js 在生成静态文件时使用 html-minifier 对 html 文件进行压缩，配置压缩的行为
         minify: {
           collapseBooleanAttributes: true,
           collapseWhitespace: false,
           decodeEntities: true,
           minifyCSS: true,
           minifyJS: true,
           processConditionalComments: true,
           removeAttributeQuotes: false,
           removeComments: false,
           removeEmptyAttributes: true,
           removeOptionalTags: true,
           removeRedundantAttributes: true,
           removeScriptTypeAttributes: false,
           removeStyleLinkTypeAttributes: false,
           removeTagWhitespace: false,
           sortAttributes: true,
           sortClassName: false,
           trimCustomFragments: true,
           useShortDoctype: true
         },
         // 直接配置的路由在 Nuxt.js 执行 generate 命令时，动态路由 会被忽略
         // routes: ['/cn', '/en', '/cn/news', '/en/news']
         // 动态参数返回 Promise 对象类型，函数回调是 callback(err, params)
         async routes (callback) {
           const langs = ['/en', '/zh']
           const baseRoutes = ['/', '/news', '/about']
           let routes=[]
           langs.map((lang) => {
             // 基础页面输出对应多语言路由
             baseRoutes.map((route) => {
               routes.push(lang + route)
             })
           })
           
           

           let res=await axios.get('http://localhost:4000/news-list?num=10&lang=en')
           res.data.list.map(item=>{
             routes.push('/en/news/'+item.id)
           })

           let resq=await axios.get('http://localhost:4000/news-list?num=10&lang=zh')
           resq.data.list.map(item=>{
             routes.push('/zh/news/'+item.id)
           })



           callback(null, routes)
         }
     }
}
